package com.molichuxing.services.infrastructure.service.impl;

import com.alibaba.fastjson.JSON;
import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.dto.TabDto;
import com.molichuxing.services.infrastructure.bean.AccidentBean;
import com.molichuxing.services.infrastructure.bean.AccidentCaseBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.AccidentCaseMapper;
import com.molichuxing.services.infrastructure.dao.AccidentMapper;
import com.molichuxing.services.infrastructure.dto.request.create.AccidentCaseCreateDto;
import com.molichuxing.services.infrastructure.dto.request.modify.AccidentCaseModifyDto;
import com.molichuxing.services.infrastructure.dto.response.AccidentCaseDto;
import com.molichuxing.services.infrastructure.dto.response.AccidentDto;
import com.molichuxing.services.infrastructure.dto.response.CarDto;
import com.molichuxing.services.infrastructure.service.AccidentCaseService;
import com.molichuxing.services.infrastructure.service.AccidentService;
import com.molichuxing.services.property.CarAccidentStatusEnum;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 事故 服务实现类
 * </p>
 *
 * @author
 * @since 2019-08-15
 */
@Service("accidentCaseService")
public class AccidentCaseServiceImpl implements AccidentCaseService {

  private static final Logger log = Logger.getLogger(AccidentCaseServiceImpl.class);

  @Resource
  private AccidentCaseMapper accidentCaseMapper;

  @Override
  public Map<Integer, AccidentCaseDto> getCarAccidentCaseList(List<Integer> accidentIds) {
      List<AccidentCaseBean> result = accidentCaseMapper.getAccidentCaseList(accidentIds);
      if(null == result || result.size() == 0) {
          return null;
      }
        return Convert.toAccidentCaseDto(result).stream().collect(Collectors.toMap(AccidentCaseDto::getId, a -> a,(k1, k2)->k1));
  }

    @Override
    public AccidentCaseDto getCarAccidentCase(Integer accidentId) {
        return Convert.toAccidentCaseDto(accidentCaseMapper.getAccidentCase(accidentId));
    }

    @Override
    public Boolean modifyAccidentCase(AccidentCaseModifyDto modifyDto) {
      int result = accidentCaseMapper.modifyAccidentCase(Convert.toAccidentCaseBean(modifyDto));
      if(result > 0) {
          return true;
      }
      return false;
    }

    @Override
    public Boolean createAccidentCase(AccidentCaseCreateDto accidentCaseCreateDto) {
        int result = accidentCaseMapper.createAccidentCase(Convert.toAccidentCaseBean(accidentCaseCreateDto));
        if(result > 0) {
            return true;
        }
        return false;
    }

    @Override
    public int updateAccidentCaseById(AccidentCaseCreateDto accidentCaseCreateDto) {
        return accidentCaseMapper.updateAccidentCaseById(Convert.toAccidentCaseBean(accidentCaseCreateDto));
    }
}
